<?php

namespace app\api\controller;


use app\hander\HelpHander;
use think\Request;

class Common extends Base
{
	/**
	 * 发送验证码
	 * @Function sendCode
	 *
	 * @param Request $request
	 *
	 * @return mixed
	 * @Author   tegic
	 * @Time     2018/6/4 12:41
	 */
	public function sendCode(Request $request)
	{
		//1 注册验证码  2登录验证码
		if (!in_array($request->post('type'), [ 1, 2 ])) {
			HelpHander::Response('发送错误', 400);
		}
		$count   = 2;//次数
		$minutes = 60;//秒
		$limit   = ( env('APP_DEBUG') == 1 ) ? true : HelpHander::limit($count, $minutes);
		if (!$limit) {
			HelpHander::Response('短信请求过于频繁', 400);
		}
		$result = send_msg($request->post('mobile'), $request->post('type'));
		if ($result !== true) {
			HelpHander::Response($result, 400);
		}
		HelpHander::Response('验证码发送成功');
	}
}
